package _03Map集合的遍历2_键值对方式;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Demo {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("三国演义","罗贯中");
        map.put("红楼梦","曹雪芹");
        //map.put("红楼梦","曹先生");//如果键相同，则值会被覆盖
        map.put("西游记","吴承恩");
        map.put("java","高斯林");

        Set<Map.Entry<String, String>> entrySet = map.entrySet();

//        Iterator<Map.Entry<String, String>> iterator = entrySet.iterator();
//        while (iterator.hasNext()){
//            Map.Entry<String, String> next = iterator.next();
//
//            System.out.println(next.getKey()+"="+next.getValue());
//        }

        for (Map.Entry<String, String> entry :entrySet){
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"="+value);
        }
    }
}
